package com.example.mybatisdemo.controller;

import com.example.common.global.BaseController;
import com.example.common.global.CommonResponse;
import com.example.mybatisdemo.dao.EmployeeMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sun.misc.ProxyGenerator;

import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author Aaron
 * @since 2022/2/23 11:25
 * <p>描述：</p>
 */
@RestController
@RequestMapping("/employee")
public class EmployeeController extends BaseController {

    private final EmployeeMapper employeeMapper;

    public EmployeeController(EmployeeMapper employeeMapper) {
        this.employeeMapper = employeeMapper;
    }

    @RequestMapping("/list")
    public CommonResponse<?> list() throws IOException {

        final byte[] bytes = ProxyGenerator.generateProxyClass(employeeMapper.getClass().getName(),
                employeeMapper.getClass().getInterfaces());
        final FileOutputStream fileOutputStream = new FileOutputStream(EmployeeMapper.class.getName() + ".class");
        fileOutputStream.write(bytes);

        return success("success.");
    }

}
